package demo;

public class Test {

    public static void swap2(MyValue myValue1,MyValue myValue2){
        int tmp  = myValue1.val;
        myValue1.val = myValue2.val;
        myValue2.val = tmp;
    }

    public static void main(String[] args) {

        MyValue myValue1 = new MyValue();
        myValue1.val = 10;
        MyValue myValue2 = new MyValue();
        myValue2.val = 20;

        System.out.println("交换前：val= " +myValue1.val + " " + "val2=" + myValue2.val);
        swap2(myValue1,myValue2);
        System.out.println("交换后：val= " +myValue1.val + " " + "val2=" + myValue2.val);
    }



    //无法按预期交换值，交换的是形参值，实参不发生变化
    public static void swap(int a, int b){
        int tmp = a;
        a = b;
        b = tmp;
    }

    public static void main3(String[] args) {
        int a = 10;
        int b = 20;
        System.out.println("交换前：a = " + a + " b = " + b);
        swap(a,b);
        System.out.println("交换后：a = " + a + " b = " + b);
    }

    public static void main2(String[] args) {
        Dog dog = new Dog("旺财",7); //执行顺序：父类静态->子类静态->父类实例代码块->父类构造方法->子类实例代码块->子类构造方法

        System.out.println("----------");

        Dog dog2 = new Dog("小黑",6); //第二个dog对象不再调用静态代码块

        System.out.println("-----------");

        Cat cat = new Cat("mimi",4); //不调用父类静态(静态只调用一次)



    }

    /*public static void main1(String[] args) {
        Dog dog = new Dog();
        dog.name = "旺财";
        dog.age = 2;
        dog.eat();
        dog.bark();

        System.out.println("-----------");

        Cat cat = new Cat();
        cat.name = "mimi";
        cat.age = 1;
        cat.eat();
        cat.mew();

    }*/
}
